package com.datastructure.test.Ispoporder;

import java.util.Stack;

public class IsPopOrder {

    public static void main(String[] args) {

    }

    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int i = 0;
        for(int pushedItem:pushA){
            stack.push(pushedItem);//入栈
            while(!stack.isEmpty() && stack.peek() == popA[i]){//循环并出栈
                stack.pop();
                i++;
            }
        }
        return stack.isEmpty();
    }
}
